package com.pet.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.common.model.PageModel;
import com.pet.system.domain.entity.SysApp;
import com.pet.system.domain.vo.SysAppVO;
import com.pet.system.mapper.SysAppMapper;
import com.pet.system.service.ISysAppService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/** @author Centaurea */
@Service
@AllArgsConstructor
public class SysAppServiceImpl implements ISysAppService {
  private final SysAppMapper appMapper;

  @Override
  public boolean save(SysApp entity) {
    int i = appMapper.insert(entity);
    return i == 1;
  }

  @Override
  public boolean delete(List<Integer> ids) {
    int i = appMapper.deleteBatchIds(ids);
    return i == ids.size();
  }

  @Override
  public boolean update(SysApp entity) {
    int i = appMapper.updateById(entity);
    return i == 1;
  }

  @Override
  public PageModel<SysApp> query(PageModel<SysApp> page, SysAppVO params) {
    QueryWrapper<SysApp> queryWrapper = new QueryWrapper<>();
    queryWrapper.like(SysApp.COL_NAME, params.getName());
    queryWrapper.like(SysApp.COL_FRONTEND, params.getFrontend());
    queryWrapper.orderByAsc();
    Page<SysApp> sysAppPage =
        appMapper.selectPage(new Page<>(page.getPageNo(), page.getLimit()), queryWrapper);
    page.setTotal(sysAppPage.getTotal());
    page.setRecords(sysAppPage.getRecords());
    return page;
  }
}
